import java.util.ArrayList;
import java.util.List;

class Solution6 {

    List<String> ret;
    StringBuffer path;

    public List<String> letterCasePermutation(String s) {
        ret = new ArrayList<>();
        path = new StringBuffer();

        dfs(s, 0);
        return ret;
    }

    public void dfs(String s, int pos){
        if(pos == s.length()){
            ret.add(path.toString());
            return ;
        }

        char ch = s.charAt(pos);
        path.append(ch);
        dfs(s, pos + 1);
        path.deleteCharAt(path.length() - 1);

        if(ch < '0' || ch > '9'){
            char tmp = change(ch);
            path.append(tmp);
            dfs(s, pos + 1);
            path.deleteCharAt(path.length() - 1);
        }
    }

    public char change(char ch){
        if(ch >= 'a' && ch <= 'z'){
            return ch -= 32;
        }else{
            return ch += 32;
        }
    }
}